/*
 * This file (AxFloatParameter.java) is protected by the GNU GPL licence (v2). 
 * Please read the license.txt attached for further informations. 
 * 
 */

package artx.parameters;

import artx.utils.AxLog;

/**
 * Float parameter class.
 * 
 * @author Xavier Gouchet
 * 
 */
public class AxFloatParameter extends AxParameter {

	/** float value of the parameter */
	protected float floatValue;

	/**
	 * Standard constructor.
	 * 
	 * @param name
	 *            name of the parameter
	 */
	public AxFloatParameter(String name) {
		super(name, "float");
	}

	/**
	 * Standard constructor.
	 * 
	 * @param name
	 *            name of the parameter
	 * @param reset
	 *            default value of the parameter
	 */
	public AxFloatParameter(String name, String reset) {
		super(name, "float", reset);
	}

	/**
	 * Get the float value of the parameter.
	 * 
	 * @return float value of the parameter
	 */
	public float GetValue() {
		return this.floatValue;
	}

	/**
	 * @see artx.parameters.AxParameter#UpdateValue()
	 */
	public boolean UpdateValue() {
		if ((this.strValue == null) || (this.strValue.isEmpty())) {
			this.floatValue = 0.0f;
			return true;
		}
		try {
			float val = Float.valueOf(this.strValue);
			this.floatValue = val;
			return true;
		} catch (NumberFormatException e) {
			AxLog.Error("Can't convert parameter " + this.NAME + "'s value \""
					+ this.strValue + "\" to float");
			return false;
		}
	}

}
